package com.one.square.user.server.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.one.square.core.domain.Result;
import com.one.square.core.entity.SysDictData;
import com.one.square.core.vo.QuerySysDictDataVo;
import com.one.square.user.server.mapper.SysDictDataMapper;
import com.one.square.user.server.service.SysDictDataService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author cwm
 * @Description
 * @date 2021/11/1 上午11:43
 * @Version 1.0
 */
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements SysDictDataService {
    @Override
    public Result<IPage<SysDictData>> list(Page<SysDictData> page, QuerySysDictDataVo querySysDictDataVo) {
        LambdaQueryWrapper<SysDictData> wrapper = Wrappers.<SysDictData>lambdaQuery()
                .eq(StrUtil.isNotEmpty(querySysDictDataVo.getDictType()), SysDictData::getDictType, querySysDictDataVo.getDictType())
                .eq(StrUtil.isNotEmpty(querySysDictDataVo.getDictLabel()), SysDictData::getDictLabel, querySysDictDataVo.getDictLabel())
                .eq(Objects.nonNull(querySysDictDataVo.getStatus()), SysDictData::getStatus, querySysDictDataVo.getStatus())
                .orderByAsc(SysDictData::getDictSort);
        return Result.succeed(this.baseMapper.selectPage(page,wrapper));
    }
}
